using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.SpaceBlock.FS;
using CodePlex.Resourceful;
using CodePlex.Resourceful.Amazon.S3;

namespace CodePlex.SpaceBlock.Tasks
{
    public class GenericS3Upload : GenericS3Base
    {

        new public class Properties : CodePlex.SpaceBlock.Tasks.GenericS3Base.Properties
        {
            public static readonly string SourcePath = "SourcePath";
            public static readonly string ContentType = "ContentType";
            public static readonly string CannedACL = "CannedACL";
        }


        protected override void InternalExecute(S3FileSystem fileSystem)
        {


            NameValuePairs metadata = new NameValuePairs();

            string contentType = this.GetTrimmed(Properties.ContentType,false);
            if (!string.IsNullOrEmpty(contentType))
            {
                metadata[HttpHeader.ContentType] =  contentType;
            }

            string cannedACL = this.GetTrimmed(Properties.CannedACL,false);
            if (!string.IsNullOrEmpty(cannedACL))
            {
                metadata[S3Constants.Headers.CannedAccessPolicy] = cannedACL;
            }



            LocalFileSystem sourceFS = new LocalFileSystem();

            Path sourcePath = sourceFS.FromLocalPath(this.GetTrimmed(Properties.SourcePath, true));

            Path destPath = Path.Parse(this.GetTrimmed(Properties.DestinationPath, true));

            this.InternalTransfer(sourceFS, fileSystem, sourcePath, destPath,metadata);


            this.LogInfo("Upload complete.");


        }
    }
}
